package main

import (
	"bytes"
	"fmt"

	"github.com/bytedance/sonic"
)

func main() {
	//testSerialize()
	testStreamInputOutput()
}

type Person struct {
	Name string
	Age  int
	Sex  int
}

func testStreamInputOutput() {
	var o1 = map[string]interface{}{
		"a": "b",
	}
	var o2 = 1
	var w = bytes.NewBuffer(nil)
	var enc = sonic.ConfigDefault.NewEncoder(w)
	err := enc.Encode(o1)
	if err != nil {
		panic(err)
	}
	err = enc.Encode(o2)
	if err != nil {
		panic(err)
	}
	fmt.Println(w.String())
}
func testSerialize() {
	var data Person = Person{
		Name: "John Doe",
		Age:  25,
		Sex:  1,
	}
	// Marshal
	output, err := sonic.Marshal(&data)
	if err != nil {
		panic(err)
	}
	fmt.Printf("序列化后的数据:%v \n", string(output))
	var dataCopy Person
	// Unmarshal
	err = sonic.Unmarshal(output, &dataCopy)
	if err != nil {
		panic(err)
	}
	fmt.Printf("反序列化后的数据:%v \n", dataCopy)
}
